package com.monitor.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.monitor.entity.ErpCustomerContact;
import com.monitor.service.ErpCustomerContactService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 客户联系人表 前端控制器
 * </p>
 *
 * @author LX
 * @since 2018-09-05
 */
@RestController
@RequestMapping("/erpCustomerContact")
@Api(description="客户联系人表")
public class ErpCustomerContactController {

    @Resource
    private ErpCustomerContactService customerContactService;

    @RequestMapping("/inertOrUpdateCustomerContact")
    @ApiOperation("添加Or修改客户客户联系人信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<ErpCustomerContact> inertOrUpdateCustomerContact(ErpCustomerContact customerCar,String ren) {
        Result<ErpCustomerContact> result=new Result<ErpCustomerContact>();
        try{
        	customerCar.setLuRuPeople(ren);
            customerContactService.insertOrUpdate(customerCar);
            result.setCount(1);
            result.setData(customerCar);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getcustContactByCustId")
    @ApiOperation("根据客户id客户联系人信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpCustomerContact>> inertOrUpdateCustomerCar(Integer custId) {
        Result<List<ErpCustomerContact>> result=new  Result<List<ErpCustomerContact>>();
        try{
            //(new EntityWrapper<ErpCustomerContact>().eq("customer_id",custId));
            List<ErpCustomerContact> customer_id = customerContactService.selectList(new EntityWrapper<ErpCustomerContact>().eq("customer_id", custId));
            result.setCount(1);
            result.setData(customer_id);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/removeCustomerContact")
    @ApiOperation("删除客户客户联系人信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "customerCarId", value = "客户联系人ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> removeCustomerContact(Integer customerCarId) {
        Result<Integer> result=new Result<Integer>();
        try{
            result.setCount(1);
            result.setData(customerContactService.deleteById(customerCarId)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }
    @RequestMapping("/getCustContactBycustIdPage")
    @ApiOperation("根据客户ID查询客户联系人信息分页")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Page<ErpCustomerContact>> getCustContactBycustIdPage(@RequestParam(value = "page", defaultValue = "1") int page,
                                                            @RequestParam(value="limit",defaultValue="10") int limit, Integer custId) {
        Result<Page<ErpCustomerContact>> result=new Result<Page<ErpCustomerContact>>();
        try{
            Page<ErpCustomerContact> page1=new Page<ErpCustomerContact>(page,limit);
            Page<ErpCustomerContact> carPage=customerContactService.selectPage(page1,new EntityWrapper<ErpCustomerContact>().eq("customer_id",custId));
            //Page<ErpCustomerCar> page=new Page<ErpCustomerCar>(1,2);
            result.setCount(carPage.getRecords().size());
            result.setData(carPage);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }



}

